package com.dpiinc.TechPage.user.logic;

//import com.wenba.sdk.OCR;


/**
 * Created by hu489_000 on 2018-08-07.
 */

public class HdrHelper {

    private static final String TAG = "HdrHelper";

//    public static void reportHdrResult(final String noteId) {
//        final StrokeList strokeList = new StrokeList();
//        NoteCacheModel noteCacheModel = PenCacheManager.getInstance().getCurrentCache();
//        if (noteCacheModel != null) {
//            noteCacheModel.readStrokesFromFile(new Function1<ArrayList<PenStroke>, Unit>() {
//                @Override
//                public Unit invoke(ArrayList<PenStroke> penStrokes) {
//                    if (penStrokes == null) {
//                        return null;
//                    }
//                    strokeList.setStrokes(penStrokes);
//                    startHandWritingRecognize(noteId, strokeList);
//                    return null;
//                }
//            });
//        }
//    }
//
//    private static void startHandWritingRecognize(final String noteId, final StrokeList strokeList) {
//        Thread myThread = new Thread(new Runnable() {
//
//            @Override
//            public void run() {
//                //识别
//                try {
//                    final OCR.RecognizeOutputDesc callBackToMeOutInfo = callOcrSdk(strokeList);
//                    if (callBackToMeOutInfo != null) {
//                        //输出结果
//                        if (HDRActivity.SUCCESS_FLAG.equals(callBackToMeOutInfo.message)) {
//                            Log.d(TAG, "SUCCESS_MESSAGE callBackToMeOutInfo.recognize_result = " + callBackToMeOutInfo.recognize_result);
////                            obtainMessageToTarget(callBackToMeOutInfo.recognize_result, SUCCESS_MESSAGE);
//                            recognizeUpload(noteId, callBackToMeOutInfo.recognize_result);
//                        } else {
////                            obtainMessageToTarget(callBackToMeOutInfo.message, ERROR_MESSAGE);
//                            Log.d(TAG, "SUCCESS_MESSAGE callBackToMeOutInfo.message = " + callBackToMeOutInfo.message);
//                        }
//                    } else {
//                        Log.d(TAG, "ERROR_MESSAGE ERROR_MESSAGE = " + "识别错误");
////                        obtainMessageToTarget(getString(R.string.recognize_error), ERROR_MESSAGE);
//                    }
//                } catch (Exception e) {
//                    e.printStackTrace();
//                }
//            }
//        });
//        // myThread.setMyThreadCallBack( this );
//        myThread.start();
//    }
//
//    private static OCR.RecognizeOutputDesc callOcrSdk(StrokeList strokeList) {
//        OCR.RecognizeInputDesc inputParams = new OCR.RecognizeInputDesc();
//        RecognizeApiKeyBean rakb = SpUtils.getRecognizeApiKeyBean(AIWriteApplication.Companion.instance());
//        if (rakb != null && !TextUtils.isEmpty(rakb.getApiId()) && !TextUtils.isEmpty(rakb.getApiKey())) {
//
//            inputParams.appid = rakb.getApiId();
//            inputParams.appkey = rakb.getApiKey();
//        } else {
//            inputParams.appid = HDRActivity.APPLICATION_ID;
//            inputParams.appkey = HDRActivity.APPLICATION_KEY;
//        }
//
//        //中英文类型选择
//        String language_type = AIWriteApplication.Companion.instance().getResources().getConfiguration().locale.getLanguage();
//        if("zh".equals(language_type)){
//            inputParams.type = OCR.type_simplified_chinese;
//        }else if("en".equals(language_type)){
//            inputParams.type = OCR.type_english;
//        }else{
//            inputParams.type = OCR.type_simplified_chinese;
//        }
//        inputParams.strokes = strokeList.getPointStr();
//        inputParams.timeout = 10 * 1000;
//        //java.lang.UnsatisfiedLinkError: dlopen failed: library "libReqCodec.so" not found
//        return OCR.recognize_online_handwriting(inputParams);
//    }
//
//    /**
//     * 提交识别结果
//     */
//    private static void recognizeUpload(final String noteId, final String result) {
////        ToastUtils.showTopTip(context,getResources().getString(R.string.recognize_result_saving));
//        HashMap<String, String> requestMap = getRecognizeUploadMap(noteId, result);
//        Observable<BaseEntity<RecognizeUploadBean>> observable = RetrofitFactory.getInstance().recognizeUpload(requestMap);
//        BaseObserver mBaseObserver = new BaseObserver<RecognizeUploadBean>(AIWriteApplication.Companion.instance()) {
//            @Override
//            protected void onHandleError(int code) {
//                super.onHandleError(code);
//                Log.d(TAG, "recognizeUpload onHandleError code = " + code);
//            }
//
//            @Override
//            protected void onHandleSuccess(RecognizeUploadBean baseBean) {
//                Log.d(TAG, "recognizeUpload onHandleSuccess RecognizeUploadBean = " + baseBean);
//
//            }
//        };
//        observable.compose(RxSchedulers.compose()).subscribe(mBaseObserver);
//    }
//
//    private static HashMap<String, String> getRecognizeUploadMap(final String noteId, String result) {
//        HashMap<String, String> params = new HashMap<String, String>();
//        params.put("uId", UserManager.INSTANCE.getUserId());
//        params.put("accessToken", UserManager.INSTANCE.getAccessToken());
//        params.put("language", String.valueOf(HDRActivity.LANGUAGE_TYPE_CHINESES));
//        params.put("noteId", noteId);
//        params.put("uploadTime", String.valueOf(System.currentTimeMillis()));
//        params.put("recgData", result);
//        return params;
//    }

}
